#include <boost/program_options.hpp>
#include <string>
#include <iostream>
#include <boost/foreach.hpp>

using namespace boost::program_options;
#define foreach BOOST_FOREACH

int main(int argc, char ** argv) {
	std::vector<std::string> input_files;
	int width, height;

	bool ray_enabled = false;
	unsigned int ray_depth;

	options_description desc("Options");
	desc.add_options()
		("help", "Show this message")
		("input,i", value<std::vector<std::string> >(&input_files), "Input file")
		("width,w", value<int>(&width)->default_value(100), "Result image width")
		("height,h", value<int>(&height)->default_value(100), "Result image height")
		("ray,r", "Enable ray tracing")
		("raydepth,rd", value<unsigned int>(&ray_depth)->default_value(0), "Ray tracing depth")
	;
	
	variables_map vm;

	positional_options_description pos;
	pos.add("input", -1);

	command_line_parser parser(argc,argv);
	parser.allow_unregistered();
	parser.options(desc).positional(pos);

	parsed_options options = parser.run();

	store(options, vm);
	notify(vm);

	std::vector<std::string> unrecognized = collect_unrecognized(options.options, exclude_positional);
	foreach(std::string opt, unrecognized) {
		std::cout << "Unrecognized option: " << opt << std::endl;
	}

	if(vm.count("help")) {
		std::cout << desc << std::endl;
		return -1;
	}

	if(vm.count("input")) {
		foreach(std::string file, input_files) {
			std::cout << "Input file: " << file << std::endl;
		}
	} else {
		std::cout << "No input files" << std::endl;
		return -1;
	}

	if(vm.count("width")) std::cout << "Width: " << width << std::endl;
	if(vm.count("height")) std::cout << "Height: " << height << std::endl;

	if(vm.count("ray")) {
		ray_enabled = true;
	}

	if(vm.count("raydepth")) std::cout << "Ray depth: " << ray_depth << std::endl;

	return 0;
}
